package com.java.dormitorymanager.mvc.view;

import com.java.dormitorymanager.pojo.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @program: DormitoryManager
 * @description: 修改学生信息界面
 * @author: ShuangChenYue
 * @create: 2021-05-17 10:28
 **/
@WebServlet(value = "/ViewUpdateStudent")
public class ViewUpdateStudentServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("通过修改按钮来此修改学生信息界面");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>修改学生</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-student/updateStudent.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/upIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\"> Manage Students</h1>");
        out.println("</div>");
        Student student = (Student) req.getAttribute("student");
        out.println("<div id=\"registerBox\">");
        out.println("<h1>Update Student</h1>");
        out.println("<form id=\"registerForm\" action=\"/DormitoryManager/mvc/updateStudent.do\" method=\"post\">");
        out.println("<table id=\"registerTable\">");
        out.println("<tr>");
        out.println("<td id=\"tdId\" colspan=\"2\"><i id=\"IdIcon\" class=\"iconfontAD\">&#xe64d;</i><input style=\"color: gray\" id=\"inputId\" type=\"text\" name=\"id\" placeholder=\"id\" readonly=\"readonly\" value="+student.getId()+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdName\" colspan=\"2\"><i id=\"nameIcon\" class=\"iconfontAD\">&#xe669;</i><input id=\"inputName\" type=\"text\" name=\"name\" placeholder=\"name\" value="+student.getName()+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdPassword\" colspan=\"2\"><i id=\"passwordIcon\" class=\"iconfontAD\">&#xe668;</i><input id=\"inputPassword\" type=\"text\" name=\"password\" placeholder=\"password\" value="+student.getPassword()+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdStunum\"><i id=\"stunumIcon\" class=\"iconfontAD\">&#xe675;</i><input id=\"inputStunum\" type=\"text\" name=\"stunum\" placeholder=\"学生编号\" value="+student.getStunum()+"></td>");
        out.println("<td id=\"tdAge\"><i id=\"ageIcon\" class=\"iconfontAD\">&#xe62f;</i><input id=\"inputAge\" type=\"text\" name=\"age\" placeholder=\"学生年龄\" value="+student.getAge()+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdGender\"><i id=\"genderIcon\" class=\"iconfontAD\">&#xe63e;</i>");
        out.println("<select id=\"selectGender\" name=\"gender\" value="+student.getGender()+">");
        out.println("<option value =\"#\">学生性别</option>");
        out.println("<option value =\"male\">male</option>");
        out.println("<option value =\"female\">female</option>");
        out.println("</select></td>");
        out.println("<td id=\"tdStatus\"><i id=\"statusIcon\" class=\"iconfontAD\">&#xe635;</i><input id=\"inputStatus\" type=\"text\" name=\"status\" placeholder=\"学生状态\" value="+student.getStatus()+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdEmail\" colspan=\"2\"><i id=\"emailIcon\" class=\"iconfontAD\">&#xe631;</i><input id=\"inputEmail\" type=\"email\" name=\"email\" placeholder=\"邮箱地址\" value="+student.getEmail()+"></td>");
        out.println("</tr>");

        out.println("<tr>");
        out.println("<td id=\"tdDorm\" colspan=\"2\"><i id=\"DormIcon\" class=\"iconfontAD\">&#xe633;</i><input id=\"inputDorm\" type=\"text\" name=\"dornum\" placeholder=\"学生宿舍\" value="+student.getDornum()+"></td>");
        out.println("</tr>");

        out.println("<tr>");
        out.println("<td id=\"tdSubmit\" colspan=\"2\"><input id=\"inputSubmit\" type=\"submit\" value=\"Update\" title=\"点击修改\"></td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</form>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
